package cn.wolfcode.education.web.controller;

import cn.wolfcode.education.anno.PermissionName;
import cn.wolfcode.education.domain.Classgrade;
import cn.wolfcode.education.query.QueryObject;
import cn.wolfcode.education.service.IClassgradeService;
import cn.wolfcode.education.util.JSONResult;
import cn.wolfcode.education.util.PageResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("classgrade")
public class ClassgradeController {
    @Autowired
    private IClassgradeService classgradeService;

    @RequestMapping("")
    public String index(){

        return "classgrade";
    }

    @RequestMapping("list")
    @ResponseBody
    @RequiresPermissions("classgrade:list")
    @PermissionName("班级列表")
    public PageResult list(QueryObject qo) {
        return classgradeService.query(qo);
    }

    //班级保存
    @PermissionName("班级保存")
    @RequiresPermissions("classgrade:save")
    @RequestMapping("save")
    @ResponseBody
    public JSONResult save(Classgrade classgrade){
        JSONResult jsonResult = new JSONResult();
        try {
            classgradeService.save(classgrade);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setMsg("系统崩溃了,攻城狮正在努力攻城!");
        }
        return jsonResult;
    }
    //班级删除
    @PermissionName("班级删除")
    @RequiresPermissions("classgrade:delete")
    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult jsonResult = new JSONResult();
        try {
            classgradeService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setMsg("系统崩溃了,攻城狮正在努力攻城!");
        }
        return jsonResult;
    }

    //班级编辑
    @PermissionName("班级编辑")
    @RequiresPermissions("classgrade:update")
    @RequestMapping("update")
    @ResponseBody
    public JSONResult update(Classgrade classgrade){
        JSONResult jsonResult = new JSONResult();
        try {
            classgradeService.update(classgrade);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setMsg("系统崩溃了,攻城狮正在努力攻城!");
        }
        return jsonResult;
    }

    //分配班主任
    @PermissionName("分配班主任")
    @RequiresPermissions("classgrade:updateTeacher")
    @RequestMapping("updateTeacher")
    @ResponseBody
    public JSONResult updateTeacher(Long id){
        JSONResult jsonResult = new JSONResult();
        try {
            classgradeService.updateTeacher(id);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setMsg("系统崩溃了,攻城狮正在努力攻城!");
        }
        return jsonResult;
    }

    @RequestMapping("queryAll")
    @ResponseBody
    public List<Classgrade> queryAll(){
        return classgradeService.queryAll();
    }

    //根据教室的id查询出班级信息
    @RequestMapping("queryByClassroomId")
    @ResponseBody
    public PageResult queryByClassroomId(Long id){
        return classgradeService.queryByClassroomId(id);
    }




    // 获取所有班级,用于客户选择意向班级
    @RequestMapping("getAllClassgrade")
    @ResponseBody
    public List<Classgrade> getAllClassgrade(){
        return classgradeService.getAllClassgrade();
    }



}
